package ui;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import po.Book;
import service.BookManager;
import service.impl.BookManagerImpl;


public class AddBookServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private BookManager bm=new BookManagerImpl();
       
   
    public AddBookServlet() {
        super();
       
    }

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//接收请求数据
		String bname=request.getParameter("bname");
		String sprice=request.getParameter("price");
		//数据类型转换
		double price=Double.parseDouble(sprice);
		//校验
		if(price<=0){
			request.getRequestDispatcher("addBook.jsp").forward(request, response);
		}
		//数据封装
		Book b = new Book(null,bname,price);
		//调用业务，并接收model
		int m=bm.addBook(b);
		//存储model到context中
		//empty.......
		
		//请求转发
		if(m<1){
			request.getRequestDispatcher("addBook.jsp").forward(request, response);
		}
		else{
			request.getRequestDispatcher("FindAllBooks").forward(request, response);
		}
		
		
		
	}

}
